package com.LeeCode;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 链表随机节点
 */

public class Code382 {
    public static void main(String[] args) {

    }

    class Solution {
        private List<Integer> list;
        private Random random;

        public Solution(ListNode head) {
            list = new ArrayList<>();
            random = new Random();
            while (head != null) {
                list.add(head.val);
                head = head.next;
            }
        }

        public int getRandom() {
            return list.get(random.nextInt(list.size()));
        }
    }
}
